###################################
## 这是一个定时给微信发送消息的程序 ##
###################################

## 需要安装的
pip3 install wxpy requests
echo y | sudo apt install xdg-utils

## 程序源码
from __future__ import unicode_literals
from threading import Timer

from wxpy import *
import random
import requests

bot = Bot()

def get_news():
    url = "http://open.iciba.com/dsapi/"
    r = requests.get(url)

    content = r.json()['content']
    note = r.json()['note']
    return content, note

def send_news():
    try:
        contents = get_news()
        my_friend = bot.friends().search(u'CK宇')[0]
        my_friend.send(contents[0])
        my_friend.send(contents[1])
        my_friend.send(u"Have a good one!")
        t = Timer(1, send_news)
        t.start()
    except:
        my_friend = bot.friends().search('CK宇')[0]
        my_friend.send(u'今天消息发送失败了')

if __name__ == "__main__":
    send_news()